package com.bkhech.netty.rabbitmq;

import com.bkhech.netty.utils.PropertiesUtil;
import com.bkhech.pojo.netty.ChatMsg;
import com.bkhech.utils.JsonUtils;

import java.util.Objects;
import java.util.Properties;

public class MessagePublisher {

    private static final Properties properties = PropertiesUtil.getInstance();

    public static void sendMsgToSave(ChatMsg msg) throws Exception {
        RabbitMQConnectUtil connectUtils = new RabbitMQConnectUtil();
        connectUtils.sendMsg(Objects.requireNonNull(JsonUtils.objectToJson(msg)),
                properties.getProperty("rabbitmq.exchange"),
                properties.getProperty("rabbitmq.routingKey"));
    }

    public static void sendMsgToOtherNettyServer(String msg) throws Exception {
        RabbitMQConnectUtil connectUtils = new RabbitMQConnectUtil();
        final String exchange = properties.getProperty("rabbitmq.chat.message.fanout.exchange");
        connectUtils.sendMsg(msg, exchange, "");
    }
}
